package com.bjesc_b2c.app.appraiset.mvp.model.impl;

import android.content.Context;

import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.mvp.model.LikeCarModel;
import com.rxretrofit_build.util.MapUtil;

import java.util.HashMap;
import java.util.List;

import master_bean.DemandCarBean;
import master_bean.FindCarBean;
import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

/**
 * Created by yidong on 2017/5/25.
 */

public class LikeCarModelImpl implements LikeCarModel {
    private CallBack callBack;
    public LikeCarModelImpl(CallBack callBack){
        this.callBack = callBack;
    }
    @Override
    public void getLikeCars(Context context, FindCarBean findBean) {
        
        HashMap<String, Object> build = new MapUtil()
                .put("page", findBean.getPage())
                .put("tou_id", findBean.getTou_id())
                .put("price", findBean.getPrice())
                .put("type", findBean.getType())
                .put("keyword", findBean.getKeyword())
                .build();
        RxRequest.request(ShowType.SHOW, RxRequest.getClient(context, build).create(IApiActivityRequest.class).getLikeCars(),
                new BaseSubscriber<TokenBean<List<DemandCarBean>>>(context) {
                    @Override
                    public void onSuccess(TokenBean<List<DemandCarBean>> o) {
                        if(callBack!=null){
                            callBack.callback(o.getData());
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                    }
                });
    }
    public interface CallBack{
        void callback(List<DemandCarBean> listbean);
    }
}
